package com.zhkj.txg.module.cart.adapter

import android.graphics.Paint
import android.text.TextUtils
import android.widget.ImageView
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.zhkj.lib.utils.AccountManager
import com.zhkj.lib.utils.SpanUtil
import com.zhkj.txg.R
import com.zhkj.txg.module.home.entity.HotGoodEntity
import com.zhkj.txg.utils.ImageUtils

class CartHotAdapter : BaseQuickAdapter<HotGoodEntity, BaseViewHolder>(R.layout.item_home_goods),
    LoadMoreModule {
    override fun convert(helper: BaseViewHolder, item: HotGoodEntity) {
        val imageView = helper.setText(R.id.tvGoodsTitle, item.goodName)
            .setText(R.id.tvGoodsPrice, SpanUtil.setMoneySymbol(item.price,true))
            .setVisible(R.id.tvGoodsTag, TextUtils.equals(item.isNew, "1"))
            .getView<ImageView>(R.id.ivGoodsThumb)
        ImageUtils.loadImage(context, imageView, item.image)
        // 设置是显示市场价还是显示分享赚多少钱
        helper.getView<TextView>(R.id.tvSellSpread).apply {
            if (AccountManager.isMember() && item.shareEarn.isNotEmpty() && item.shareEarn != "0") {
                setTextColor(ContextCompat.getColor(context, R.color.colorMain))
                paint.flags = Paint.ANTI_ALIAS_FLAG
                text = SpanUtil.setPrefixMoneyStr(price = item.shareEarn)
            } else {
                setTextColor(ContextCompat.getColor(context, R.color.colorLightText))
                paint.flags = Paint.STRIKE_THRU_TEXT_FLAG
                paint.isAntiAlias = true
                text = SpanUtil.setMoneySymbol(item.marketPrice)
            }
        }
    }
}